package com.example.SocialApplication.service;

import android.os.AsyncTask;
import com.example.SocialApplication.constants.URLs;
import com.example.SocialApplication.db.entity.User;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by differ on 25.08.13.
 */
public class CallServiceGetFacebookUsers extends AsyncTask<Void, Void, List<User>> implements URLs {

    public CallServiceGetFacebookUsers() {
    }

    @Override
    protected List<User> doInBackground(Void... params) {
        String url = GET_FB_USERS_URL;
        String result = "";
        try {
            result = HttpServices.callHttpGetRequest(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        List<User> list = null;
        if (!result.equals("")) {
            Gson gson = new Gson();
            Type listType = new TypeToken<ArrayList<User>>(){}.getType();
            list = gson.fromJson(result, listType);
        }
        return list;
    }
}
